<?php
//添加水印(兼容图片格式)
$imagepath ="../../public/imgs/1.jpg";
$img= getimagesize($imagepath);
if($img == FALSE){
	exit("资源非法！！");
}
list($width,$height) = $img;
//截取扩展名
$ext = substr($imagepath, strrpos($imagepath,".")+1);
if($ext =="jpg"){
	$type= "imagecreatefromjpeg";
	$out = "imagejpeg";
	header("content-type:image/jpeg");
}elseif($ext =="png"){
	$type= "imagecreatefrompng";
	$out = "imagepng";
	header("content-type:image/png");
}elseif($ext =="gif"){
	$type= "imagecreatefromgif";
	$out = "imagegif";
	header("content-type:image/gif");
}
//图片加水印
$image = $type($imagepath);
$color = imagecolorallocate($image, 0, 0, 0);
imagettftext($image, 30, 10, $width-30*6, $height-20, $color, "C:/Windows/Fonts/simhei.ttf", "请勿转载");
$out($image);
imagedestroy($image);
//$out($image,"imgs/9.jpg");//加第二个参数后会保存带水印的图片,并且不再在页面上输出图片
  

